package Controlador;

import java.io.IOException;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Model.Digitalizar;
import Model.Digitalizar;
import Repositorio.DigitalizarRepositorio;
import Repositorio.UsuarioRepositorio;

/**
 * Servlet implementation class DigitalizarServlet
 */
@WebServlet("/DigitalizarServlet")
public class DigitalizarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DigitalizarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		String acao = request.getParameter("logica");
		
		if(acao.equals("cadastrar_digitalizacao")){
			
				RequestDispatcher view = request.getRequestDispatcher("cadastrar_digitalizacao.jsp");
				view.forward(request, response);
			}
		if(acao.equals("cadastro_digitalizacao")){
			cadastrarDigitalizacao(request,response);
		}
			
			
		}
	
	protected void cadastrarDigitalizacao(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Digitalizar digitalizar = new Digitalizar();
		digitalizar.setDate(new Date());
		digitalizar.setDigitalizar(digitalizar);
		DigitalizarRepositorio digitalizarRepositorio = new DigitalizarRepositorio();
		digitalizarRepositorio.inserirDigitalizacao(digitalizar);
		RequestDispatcher view = request.getRequestDispatcher("home.jsp");
		view.forward(request, response);
	}
}

